import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:im_demo/app/constant/storage_key.dart';

import '../../../../utils/logger_util.dart';
import '../../../data/chat/api/api.dart';
import '../../../data/chat/api/response/base_response.dart';

class AuthTestController extends GetxController {
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void auth() async {
    await GetStorage().write(StorageKey.TOKEN, '');
    _getUserInfo();
  }

  void _getUserInfo() async {
    EasyLoading.show(status: '正在获取用户信息', maskType: EasyLoadingMaskType.black);

    final result = await Api().getUserInfo();
    logE('getUserInfo()->result:$result');
    EasyLoading.dismiss();

    if (result.isSuccess) {
      BaseResponse? resp = result.data;
      logE(
        'getUserInfo()->resp:code:${resp?.code},message:${resp?.message},data:${resp?.data}',
      );

      final getUserInfoResponse = resp?.data;
      logE('getUserInfo()->loginResponse:$getUserInfoResponse');

      EasyLoading.showToast('用户信息获取成功');
    } else {
      EasyLoading.showToast(
        '用户信息获取失败!${result.error?.code},${result.error?.message}',
      );
    }
  }
}
